package com.kehutong.common.util;

import com.kehutong.common.DoveClient;
import com.kehutong.common.enums.CropPattern;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.util.Ioc;

/**
 * 获取公司业务信息辅助类
 * @author: liukunlong
 * @date: 2021-09-16 11:11
 */
public class CorpUtils {
    private static final Logger logger = LoggerFactory.getLogger(CorpUtils.class);

    /**
     * 获取公司信息模块
     * @param corpNo
     * @return
     * @throws Exception
     */
    public static CropPattern getCropPattern(String corpNo) throws Exception{
        logger.info("获取公司信息数据模式---------------------------------------begin");
        // 公司信息模式  0.第三方 1.内建
        CropPattern pattern=CropPattern.THIRD;
        String cropPattern="0";
        DoveClient doveClient = Ioc.getInstance(DoveClient.class);
        JSONObject corpResult = doveClient.post("/admin/service/corp/get", (http) -> {
            http.addParam("id",corpNo);
        });
        if (corpResult.getIntValue("code") == 200) {
            JSONObject data = corpResult.getJSONObject("data");
            JSONObject cropPatternJson=data.getJSONObject("pattern");
            cropPattern=cropPatternJson.getString("id");
            return CropPattern.getGenderById(cropPattern);
        }
        logger.info("获取公司信息数据模式结果{}---------------------------------------",pattern);
        logger.info("获取公司信息数据模式---------------------------------------end");
        return pattern;
    }
}
